/*
 * Copyright 2017-2101 Innel.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hykj.xxltest.service;

import com.hykj.xxltest.base.BaseService;
import com.hykj.xxltest.base.MsgException;
import com.hykj.xxltest.mapper.AdminMapper;
import com.hykj.xxltest.model.AdminModel;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 管理员
 *
 * @author innel
 * @email 2638086622@qq.com
 * @date 2018-02-27 10:51:25
 */
@Service
public class AdminService extends BaseService<AdminModel, AdminMapper> {

    @Override
    protected void checkIllegal(AdminModel model) throws MsgException {
        if(StringUtils.isNotEmpty(model.getUsername())){//判断用户名是否重复
            Map conditon=new HashMap();
            conditon.put("username",model.getUsername());
            List<AdminModel> list = getListLite(conditon);
            if(list.size()>0){
                AdminModel user=list.get(0);
                if(!user.getId().equals(model.getId())){
                    throw new MsgException("该用户名已注册");
                }
            }
        }
    }
}